package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.News;
import cn.wolfcode.trip.base.domain.NewsComment;
import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.query.NewsCommentQuery;
import cn.wolfcode.trip.base.query.NewsQuery;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.service.INewsCommentService;
import cn.wolfcode.trip.base.service.INewsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("news")
public class NewsController {
    @Autowired
    private INewsService newsService;

    @Autowired
    private INewsCommentService commentService;

    /**
     * 查询所有已发布的的日报列表
     * @param qo
     * @return
     */
    @GetMapping
    @ResponseBody
    public Object list(NewsQuery qo){
        qo.setState(News.STATE_RELEASE);//状态是已发布的
        qo.setOrderBy("releaseTime desc");//按发布时间倒序
        qo.setPageSize(6);
        return newsService.query(qo);
    }

    /**
     * 根据newsId查询文章内容
     * @param newsId
     * @return
     */
    @GetMapping("/{newsId}/content")
    @ResponseBody
    public Object selectContentByNewsId(@PathVariable Long newsId){
        return newsService.getNewsContentById(newsId);
    }


    /*//查询日报的内容评论
    @GetMapping("/newsComment")
    public Object newsComment(NewsCommentQuery qo) {
        PageInfo data = commentService.newsComment(qo);
        return data;
    }*/

    //获取指定文章中的所有评论
    @GetMapping("/newsComment")
    @ResponseBody
    public Object listStrategyComments(NewsCommentQuery qo) {
        PageInfo pageInfo = commentService.queryForApp(qo);

        return pageInfo;
    }


    //获取某个评论详情
    @GetMapping("/comments/{commentId}")
    @ResponseBody
    public Object get(@PathVariable("commentId") Long newsCommentId) {
        NewsComment comment = commentService.getNewsCommentById(newsCommentId);
        return comment;
    }


}
